package com.xingkeduo.business.transformation.json;

import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.xingkeduo.pojo.dto.CraftsmanFileDTO;
import com.xingkeduo.util.pojo.base.BaseJson;
import com.xingkeduo.util.tool.CommonUtil;

import java.util.Iterator;
import java.util.List;

/**
 * @Description:
 * @Author:gaozifeng
 * @Date 2019/6/10 21:05
 **/
public class CraftsmanFileDTOJTO extends BaseJson {


    /**
     * 返回实体信息
     *
     * @param table:
     * @return : com.fasterxml.jackson.databind.node.ObjectNode
     * @author : gaozifeng
     * @date : 2019年4月23日10:54:28
     */
    public static ObjectNode toJson(CraftsmanFileDTO table) throws Throwable {
        ObjectNode root = MAPPER.createObjectNode();

        if (table != null) {

            root.put("path", table.getPath());
            root.put("type", table.getType());
            root.put("jobseekerId", table.getJobseeker_id());
            root.put("jobseekerCode", table.getCode());
            if(null != table.getCraftsmanName()){
                root.put("craftsName", table.getCraftsmanName());
//                root.put("craftsName", table.getCraftsmanName());
            }
            if(null != table.getName()){
//                root.put("name", table.getName());
                root.put("name", table.getName());
            }
            toBaseJson(root, table);
        }

        return root;
    }

    public static ArrayNode toJson(List<CraftsmanFileDTO> tables) throws Throwable {
        ArrayNode root = MAPPER.createArrayNode();

        if (!CommonUtil.isEmpty(tables))
            for (Iterator<CraftsmanFileDTO> iterator = tables.iterator(); iterator.hasNext(); ) {
                root.add(toJson(iterator.next()));
            }

        return root;
    }
}
